﻿using System;
using System.Net;
using SharpShare.Afp.Protocol.Security;
using SharpShare.Storage;
using SharpShare.Storage.Security;
using SharpShare.Utilities.NodeTracking;
using System.Collections.Generic;

namespace SharpShare.Afp.Protocol {
    public enum AfpSessionMessageType {
        Login, // Message for user right after login.
        Server // Message for user after sending server message available notification.
    }

    public interface IAfpSession {
        event EventHandler TransportChanged;
        event EventHandler SessionClosed;

        IAfpServer Server { get; }

        IAfpUser User { get; }

        bool HasTransport { get; }

        EndPoint Endpoint { get; }

        AfpPropertyCollection Properties { get; }

        StorageAccessList GetAccess(IStorageItem item);

        TokenAssigner<int, Guid> UserGroupAssigner { get; }

        IAfpFork OpenFork(IAfpVolume volume, IStorageFile file, AfpAccessModes accessMode, bool resource);
        IAfpFork GetFork(short id);
        IEnumerable<IAfpFork> ListForks();

        IAfpVolume OpenVolume(IStorageProvider provider);
        IAfpVolume GetVolume(ushort id);

        void Login(string version, string uam, IAfpUser user);
        void Logout();

        void Close();

        IAfpUserAuthenticationMethod AuthenticationMethod { get; set; }

        uint AttentionQuantum { get; set; }
        AfpToken? ClientToken { get; set; }
        AfpToken? ServerToken { get; set; }
        int? Timestamp { get; set; }

        void Recover(IAfpSession otherSession);

        void Notify(AfpUserBytes bytes, ushort argument, Action<AfpResultCode> replyHandler = null);

        string DequeueMessage(AfpSessionMessageType type);

        bool SendMessage(string message, TimeSpan timeout);

        bool IsSleeping { get; set; }
    }
}
